public class TestDemo9 {
    public static void binarySearch(int[] array, int k){
        int left = 0;
        int right = array.length - 1;
        while(left <= right){
            int mid = (left + right) / 2;
            if(array[mid] == k){
                System.out.println("找到了是下标"+ mid);
                break;
            }else if(array[mid] > k){
                right = mid - 1;
            }else{
                left = mid + 1;
            }
        }
        if(left > right){
            System.out.println("不存在这个数");
        }
    }
    public static void main(String[] args) {
        int[] array = {1,2,3,4,5};
        binarySearch(array,3);
    }
}
